package org.op.service.doc;

import java.util.ArrayList;
import java.util.List;

public class ReplaceTextServiceImpl implements ReplaceTextService {

	public List<String> replaceText(List<String> content, String searchText,
			String replaceText) {
		
		System.out.println("Replacing " + searchText + " with " + replaceText);
		
		List<String> replacedContent = new ArrayList<String>();
		StringBuffer newLine = new StringBuffer("");
		int i = 0;
		for (String line : content) {
			// TODO - use a regex to do the replacement
			newLine = new StringBuffer("");
			i = line.indexOf(searchText);
			while (i>=0) {
				newLine.append(line.substring(0,i));
				newLine.append(replaceText);
				line = line.substring(i + searchText.length());
				i = line.indexOf(searchText);
			}
			newLine.append(line.toString());
			replacedContent.add(newLine.toString());
		}
		return replacedContent;
	}

}
